#include "native-lib.h"
#include "device_communication.grpc.pb.h"
#include "server_base.h"
#include <memory>
#include <string>

class Server : public ServerBase {
public:
  Server() = default;
  ~Server() override = default;

protected:
  void GetPlatformInfo(std::string &platform, std::string &deviceModel,
                       std::string &systemVersion) override {
    platform = "iOS";
    deviceModel = "Unknown";
    systemVersion = "Unknown";
  }
};

static std::unique_ptr<Server> gServer;
static int gPort = 0;

int StartGRPCServer(int port) {
  if (gServer) {
    return false;
  }
  gServer = std::make_unique<Server>();
  gPort = port;
  return gServer->StartServer(std::to_string(gPort));
}

void StopGRPCServer() {
  if (gServer) {
    gServer->StopServer();
    gServer.reset();
    gPort = 0;
  }
}

int GetGRPCServerPort() { return gPort; }
